package com.jy.admin.db.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.jy.admin.db.dao.CeOrdersDao;
import com.jy.admin.db.entity.BogLogEntity;
import com.jy.admin.db.entity.CeOrdersEntity;
import com.jy.admin.enums.UnPushedListBean;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: anonymous
 * Date: 2022-01-03
 * Time: 18:14:20.170
 */

@Repository
public class CeOrdersDaoImpl extends AbstractBaseMapper<CeOrdersEntity> implements CeOrdersDao {

    @Override
    public void updateOrderStatus(String agentCode, Integer originStatus, Integer targetStatus) {
        Map<String, Object> params = new HashMap<>();
        params.put("originStatus", originStatus);
        params.put("targetStatus", targetStatus);
        params.put("agentCode", agentCode);
        getSqlSession().update(this.getStatement("updateOrderStatus"), params);
    }

    @Override
    public void updateAnomaly() {
        Map<String, Object> params = new HashMap<>();
        getSqlSession().update(this.getStatement("updateAnomaly"), params);
    }

    @Override
    public List<CeOrdersEntity> getTodayListByStatusAndAgent(String agentCode, Integer status) {
        Map<String, Object> params = new HashMap<>();
        params.put("status", status);
        params.put("agentCode", agentCode);
        return getSqlSession().selectList(this.getStatement("getTodayListByStatusAndAgent"), params);
    }

    @Override
    public List<CeOrdersEntity> getListByStatusAndAgent(String agentCode, Integer status) {
        Map<String, Object> params = new HashMap<>();
        params.put("status", status);
        params.put("agentCode", agentCode);
        return getSqlSession().selectList(this.getStatement("getListByStatusAndAgent"), params);
    }

    @Override
    public List<CeOrdersEntity> getTodayListByStatusAndAgentMore(String agentCode, List<Integer> status) {
        Map<String, Object> params = new HashMap<>();
        params.put("status", status);
        params.put("agentCode", agentCode);
        return getSqlSession().selectList(this.getStatement("getTodayListByStatusAndAgentMore"), params);
    }

    @Override
    public List<CeOrdersEntity> getTodayListByAgent(String agentCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("agentCode", agentCode);
        return getSqlSession().selectList(this.getStatement("getTodayListByAgent"), params);
    }

    @Override
    public List<CeOrdersEntity> getTodayPendingOrder(String status,String syncStatus) {
        Map<String, Object> params = new HashMap<>();
        params.put("status", status);
        params.put("syncStatus", syncStatus);
        return getSqlSession().selectList(this.getStatement("getTodayPendingOrder"), params);
    }

    @Override
    public void updateTodayPendingOrder(Integer status, Integer syncStatus, String orderNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("status", status);
        params.put("syncStatus", syncStatus);
        params.put("orderNo", orderNo);
        getSqlSession().update(this.getStatement("updateTodayPendingOrder"), params);

    }

    @Override
    public List<CeOrdersEntity> getTodayListBySyncStatusAndAgent(String agentCode, Integer status) {
        Map<String, Object> params = new HashMap<>();
        params.put("status", status);
        params.put("agentCode", agentCode);
        return getSqlSession().selectList(this.getStatement("getTodayListBySyncStatusAndAgent"), params);
    }

    @Override
    public List<CeOrdersEntity> getNotSendNoteOrder(String merchantCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("merchantCode", merchantCode);
        return getSqlSession().selectList(this.getStatement("getNotSendNoteOrder"), params);
    }

    @Override
    public List<UnPushedListBean> getUnPushedList(String merchantCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("merchantCode", merchantCode);
        return getSqlSession().selectList(this.getStatement("getUnPushedList"), params);
    }

    @Override
    public Integer anomalyCount() {
        Map<String, Object> params = new HashMap<>();
        return getSqlSession().selectOne(this.getStatement("anomalyCount"), params);
    }

    @Override
    public CeOrdersEntity getOneByCollectionNo(String collectionNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("collectionNo", collectionNo);
        return getSqlSession().selectOne(this.getStatement("getOneByCollectionNo"), params);
    }

    @Override
    public CeOrdersEntity getOneByOrderNo(String orderNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("orderNo", orderNo);
        return getSqlSession().selectOne(this.getStatement("getOneByOrderNo"), params);
    }

    @Override
    public CeOrdersEntity getOneByOrderNoAndAgentCode(String orderNo, String agentCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("orderNo", orderNo);
        params.put("agentCode", agentCode);
        return getSqlSession().selectOne(this.getStatement("getOneByOrderNoAndAgentCode"), params);
    }

    @Override
    public CeOrdersEntity getTodayOneByOrderNo(String orderNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("orderNo", orderNo);
        return getSqlSession().selectOne(this.getStatement("getTodayOneByOrderNo"), params);
    }

    @Override
    public CeOrdersEntity getTodayOneByOrderNoAndAgentCode(String orderNo, String agentCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("orderNo", orderNo);
        params.put("agentCode", agentCode);
        return getSqlSession().selectOne(this.getStatement("getTodayOneByOrderNoAndAgentCode"), params);
    }

    @Override
    public CeOrdersEntity getTodayOneByOrderNoAndMerchantCode(String orderNo, String merchantCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("orderNo", orderNo);
        params.put("merchantCode", merchantCode);
        return getSqlSession().selectOne(this.getStatement("getTodayOneByOrderNoAndMerchantCode"), params);
    }

    @Override
    public void updatePendingSendStatusByWaId(Integer sendStatus, String waId) {
        Map<String, Object> params = new HashMap<>();
        params.put("sendStatus", sendStatus);
        params.put("waId", waId);
        getSqlSession().update(this.getStatement("updatePendingSendStatusByWaId"), params);
    }

    @Override
    public void updatePendingRecordStatusByCollectionNo(Integer sendStatus, String collectionNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("sendStatus", sendStatus);
        params.put("collectionNo", collectionNo);
        getSqlSession().update(this.getStatement("updatePendingRecordStatusByCollectionNo"), params);
    }

    @Override
    public void updatePendingRecordResultTypeByCollectionNo(Integer resultType, String collectionNo, String result) {
        Map<String, Object> params = new HashMap<>();
        params.put("resultType", resultType);
        params.put("collectionNo", collectionNo);
        params.put("result", result);
        getSqlSession().update(this.getStatement("updatePendingRecordResultTypeByCollectionNo"), params);
    }

    @Override
    public List<BogLogEntity> getNeedPendingOrders() {
        Map<String, Object> params = new HashMap<>();
        return getSqlSession().selectList(this.getStatement("getNeedPendingOrders"), params);
    }



    @Override
    public void updateCollectionSystemRemainMoney(String tradeNo, String remainMoney) {
        Map<String, Object> params = new HashMap<>();
        params.put("tradeNo", tradeNo);
        params.put("remainMoney", remainMoney);
        getSqlSession().update(this.getStatement("updateCollectionSystemRemainMoney"), params);
    }

    @Override
    public void updateCollectionMobile(String tradeNo, String mobile) {
        Map<String, Object> params = new HashMap<>();
        params.put("tradeNo", tradeNo);
        params.put("mobile", mobile);
        getSqlSession().update(this.getStatement("updateCollectionMobile"), params);
    }
    @Override
    public void updateCollectionName(String tradeNo, String name) {
        Map<String, Object> params = new HashMap<>();
        params.put("tradeNo", tradeNo);
        params.put("name", name);
        getSqlSession().update(this.getStatement("updateCollectionName"), params);
    }

    @Override
    public void updateCollectionAppName(String name, String originNo, String clientCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("name", name);
        params.put("originNo", originNo);
        params.put("clientCode", clientCode);
        getSqlSession().update(this.getStatement("updateCollectionAppName"), params);
    }

    @Override
    public void updateCollectionContactUrl(String url, String originNo, String clientCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("url", url);
        params.put("originNo", originNo);
        params.put("clientCode", clientCode);
        getSqlSession().update(this.getStatement("updateCollectionContactUrl"), params);
    }

    @Override
    public void updateImages(String originNo, String newImg, String clientCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("originNo", originNo);
        params.put("newImg", newImg);
        params.put("clientCode", clientCode);
        getSqlSession().update(this.getStatement("updateImages"), params);
    }

    @Override
    public void updateAppLink(String originNo, String appLink, String clientCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("originNo", originNo);
        params.put("appLink", appLink);
        params.put("clientCode", clientCode);
//        Integer count = getSqlSession().selectOne(this.getStatement("countAppLink"), params);
        getSqlSession().update(this.getStatement("updateAppLink"), params);
    }

    @Override
    public void deletedRepaymentOrder() {
        Map<String, Object> params = new HashMap<>();
        getSqlSession().update(this.getStatement("deletedRepaymentOrder"), params);
    }
}